package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.happy.cat.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.UserOpinion;
import com.happy.cat.project.system.service.IUserOpinionService;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.happy.cat.framework.web.page.TableDataInfo;

/**
 * 用户意见反馈Controller
 *
 * @author verne
 * @date 2020-08-23
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userOpinion" )
@Api("用户意见反馈 API")
public class UserOpinionController extends BaseController {

    private final IUserOpinionService iUserOpinionService;

    /**
     * 查询用户意见反馈列表
     */
    @ApiOperation(value = "查询用户意见反馈列表",notes = "查询用户意见反馈列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userOpinion:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserOpinion userOpinion)
    {
        startPage();
        LambdaQueryWrapper<UserOpinion> lqw = new LambdaQueryWrapper<UserOpinion>();
        if (userOpinion.getAccountId() != null){
            lqw.eq(UserOpinion::getAccountId ,userOpinion.getAccountId());
        }
        if (StringUtils.isNotBlank(userOpinion.getProblemType())){
            lqw.eq(UserOpinion::getProblemType ,userOpinion.getProblemType());
        }
        if (StringUtils.isNotBlank(userOpinion.getProblemImgs())){
            lqw.eq(UserOpinion::getProblemImgs ,userOpinion.getProblemImgs());
        }
        if (StringUtils.isNotBlank(userOpinion.getProblemText())){
            lqw.eq(UserOpinion::getProblemText ,userOpinion.getProblemText());
        }
        if (StringUtils.isNotBlank(userOpinion.getContact())){
            lqw.eq(UserOpinion::getContact ,userOpinion.getContact());
        }
        if (StringUtils.isNotBlank(userOpinion.getReplyText())){
            lqw.eq(UserOpinion::getReplyText ,userOpinion.getReplyText());
        }
        if (userOpinion.getReplyTime() != null){
            lqw.eq(UserOpinion::getReplyTime ,userOpinion.getReplyTime());
        }
        if (StringUtils.isNotBlank(userOpinion.getReplyBy())){
            lqw.eq(UserOpinion::getReplyBy ,userOpinion.getReplyBy());
        }
        List<UserOpinion> list = iUserOpinionService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出用户意见反馈列表
     */
    @ApiOperation(value = "导出用户意见反馈列表",notes = "导出用户意见反馈列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOpinion:export')" )
    @Log(title = "用户意见反馈" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserOpinion userOpinion) {
        LambdaQueryWrapper<UserOpinion> lqw = new LambdaQueryWrapper<UserOpinion>(userOpinion);
        List<UserOpinion> list = iUserOpinionService.list(lqw);
        ExcelUtil<UserOpinion> util = new ExcelUtil<UserOpinion>(UserOpinion. class);
        return util.exportExcel(list, "userOpinion" );
    }

    /**
     * 获取用户意见反馈详细信息
     */
    @ApiOperation(value = "获取用户意见反馈详细信息",notes = "获取用户意见反馈详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOpinion:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserOpinionService.getById(id));
    }

    /**
     * 新增用户意见反馈
     */
    @ApiOperation(value = "新增用户意见反馈",notes = "新增用户意见反馈",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOpinion:add')" )
    @Log(title = "用户意见反馈" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserOpinion userOpinion) {
        return toAjax(iUserOpinionService.save(userOpinion) ? 1 : 0);
    }

    /**
     * 修改用户意见反馈
     */
    @ApiOperation(value = "修改用户意见反馈",notes = "修改用户意见反馈",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOpinion:edit')" )
    @Log(title = "用户意见反馈" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserOpinion userOpinion) {
        return toAjax(iUserOpinionService.updateById(userOpinion) ? 1 : 0);
    }

    /**
     * 删除用户意见反馈
     */
    @ApiOperation(value = "删除用户意见反馈",notes = "删除用户意见反馈",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userOpinion:remove')" )
    @Log(title = "用户意见反馈" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserOpinionService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
